import skipFormatting from "@vue/eslint-config-prettier/skip-formatting";
import { defineConfigWithVueTs, vueTsConfigs } from "@vue/eslint-config-typescript";
import { globalIgnores } from "eslint/config";
import simpleImportSort from "eslint-plugin-simple-import-sort";
import unusedImports from "eslint-plugin-unused-imports";
import pluginVue from "eslint-plugin-vue";
// const autoImportConfig = require("./.eslintrc-auto-import.json");

// To allow more languages other than `ts` in `.vue` files, uncomment the following lines:
// import { configureVueProject } from '@vue/eslint-config-typescript'
// configureVueProject({ scriptLangs: ['ts', 'tsx'] })
// More info at https://github.com/vuejs/eslint-config-typescript/#advanced-setup

export default defineConfigWithVueTs(
    {
        name: "app/files-to-lint",
        files: ["**/*.{ts,mts,tsx,vue}"]
    },

    globalIgnores(["**/dist/**", "**/dist-ssr/**", "**/coverage/**"]),

    pluginVue.configs["flat/essential"],
    vueTsConfigs.recommended,

    skipFormatting,

    {
        files: ["**/*.{ts,mts,tsx,vue}"],
        plugins: {
            "simple-import-sort": simpleImportSort,
            "unused-imports": unusedImports
        },
        languageOptions: {
            globals: {
                // 添加自动导入的全局变量，避免 eslint 报错
                // ...autoImportConfig.globals
            }
        },
        rules: {
            "simple-import-sort/imports": "error", // 强制导入语句排序
            // "simple-import-sort/exports": "error", // 强制导出语句排序
            "unused-imports/no-unused-imports": "error", // 禁止未使用的导入，eslint修复时会自动删除未使用的导入
            "unused-imports/no-unused-vars": [
                // 不禁止导入但未使用的变量，只是警告
                "warn",
                { vars: "all", varsIgnorePattern: "^_", args: "after-used", argsIgnorePattern: "^_" }
            ],
            "@typescript-eslint/no-unused-vars": [
                // 不禁止未使用的变量，只是警告
                "warn",
                { vars: "all", varsIgnorePattern: "^_", args: "after-used", argsIgnorePattern: "^_" }
            ],
            // 禁用 Vue 组件名必须为多单词的规则
            "vue/multi-word-component-names": "off",
            // 禁用 TypeScript 中禁止使用 any 类型的规则
            "@typescript-eslint/no-explicit-any": "off",
            // 禁用 TypeScript 中禁止使用 @ts-comment 指令的规则
            "@typescript-eslint/ban-ts-comment": "off",
            // 禁用禁止使用未声明变量的规则
            "no-undef": "off",
            // 禁用 Vue 中优先从 vue 包导入的规则
            "vue/prefer-import-from-vue": "off",
            // 禁用禁止使用原型内置方法的规则
            // "no-prototype-builtins": "off",
            // 禁用优先使用展开语法的规则
            "prefer-spread": "off",
            // 禁用 TypeScript 中禁止使用非空断言操作符的规则
            "@typescript-eslint/no-non-null-assertion": "off",
            // 禁用 TypeScript 中禁止在可选链中使用非空断言的规则
            "@typescript-eslint/no-non-null-asserted-optional-chain": "off"
        }
    }
);
